package simulator.ui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;

import javax.swing.JComponent;

import simulator.Scenario;

public class CycleCounter extends JComponent implements SimulationListener
{
   private static final long serialVersionUID = 1L;
   private static final Color defaultColor = new Color(100, 100, 100);
   private SimulationController controller = null;
   
   public CycleCounter(SimulationController controller)
   {
      this.controller = controller;
      this.controller.addSimulationListener(this);
   }
   
   public Dimension getPreferredSize()
   {
      return new Dimension(150, 50);
   }
   
   public void paintComponent(Graphics g)
   {
      super.paintComponent(g);  
      
      Graphics2D area = (Graphics2D) g;
      
      area.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
      area.setColor(new Color(230, 230, 255));
      area.fillRect(0, 5, 120, 40);

      area.setColor(new Color(200, 200, 230));
      area.drawRect(0, 5, 120, 40);
      
      
      Font font2 = new Font("Arial", Font.PLAIN, 12);
      area.setFont(font2);
      
      area.setColor(defaultColor);
      area.drawString("CLOCK CYCLE", 10, 18);
      
      Font font = new Font("Arial", Font.BOLD, 24);
      area.setFont(font);
      
      String cycle = "---";
      
      Scenario scenario = controller.getScenario();
      
      if (scenario != null)
      {
         cycle = scenario.getCurrentStep() + "";   
      }
      
      area.drawString(cycle, 10, 38);            
   }

   public void onScenarioChanged()
   {
      repaint();      
   }
   
   public void onScenarioStart()
   {
      
   }
   
   public void onScenarioStop()
   {
      
   }
}
